package service.impl;

import mapper.VersionMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.AppVersion;
import service.VersionService;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class VersionServiceImpl implements VersionService {
    @Resource
    private VersionMapper versionMapper;

    @Override
    public AppVersion sel(Integer id) {
        return versionMapper.sel(id);
    }

    @Override
    public List<AppVersion> selList(Integer appId) {
        return versionMapper.selList(appId);
    }

    @Override
    public int add(AppVersion appVersion) {
        int result = 0;
        try{
            if(versionMapper.add(appVersion) > 0){
                versionMapper.upVersionId(appVersion.getId(),appVersion.getAppId());
                result = 1;
            }
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public AppVersion view(Integer id) {
        return versionMapper.view(id);
    }

    @Override
    public int update(AppVersion appVersion) {
        int result = 0;
        try{
            if(versionMapper.update(appVersion) > 0){
                result = 1;
            }
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }
}
